library(ggplot2)
library(ggthemes)
# Basic plot
p <- ggplot(mpg, aes(x=displ, y=hwy, color=class)) +
geom_point() +
labs(title="Default Theme")
p
May 31, 2024
In this document, we will explore various themes and styles available in ggplot2.
library(ggplot2)
library(ggthemes)
# Basic plot
p <- ggplot(mpg, aes(x=displ, y=hwy, color=class)) +
geom_point() +
labs(title="Default Theme")
p
Below are examples of applying different themes to your plot:
custom_theme <- theme(
plot.title = element_text(size=14, face="bold", hjust=0.5),
axis.title = element_text(size=12, face="bold"),
axis.text = element_text(size=10),
panel.background = element_rect(fill="white"),
panel.grid.major = element_line(color="grey", size=0.5),
panel.grid.minor = element_line(color="lightgrey", size=0.25)
)Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
ℹ Please use the `linewidth` argument instead.
